package com.ruoyi.car.service.impl;



import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.car.pojo.TPartPatternAssembly;
import com.car.pojo.TPartPatternAssemblyModel;
import com.ruoyi.car.mapper.TPartPatternAssemblyMapper;
import com.ruoyi.car.mapper.TPartPatternAssemblyModelMapper;
import com.ruoyi.car.service.BatteryServiceinter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Transactional
@Service(value = "battery")
public class BatteryServiceimpl implements BatteryServiceinter {

    @Autowired
    private TPartPatternAssemblyMapper tPartPatternAssemblyMapper;
    @Autowired
    private TPartPatternAssemblyModelMapper tPartPatternAssemblyModelMapper;
//    @Autowired
//    private IdWorker idWorker;

    public List<TPartPatternAssembly> findAllpatternAssmbly(){

        return tPartPatternAssemblyMapper.selectList(null);
    }
    public List<TPartPatternAssemblyModel> findAllpatternAssmblyModel(){

        return tPartPatternAssemblyModelMapper.selectList(null);
    }

    @Override
    public int addSave(TPartPatternAssembly tPartPatternAssembly) {
        tPartPatternAssembly.setPatternAssemblyId(IdWorker.getId()+"");
        System.out.println(tPartPatternAssembly.getPatternAssemblyId());

        tPartPatternAssemblyMapper.insert(tPartPatternAssembly);
        return 1;
    }

    @Override
    public int addSaveModel(TPartPatternAssemblyModel tPartPatternAssemblyModel) {
        tPartPatternAssemblyModel.setPatternAssemblyId(IdWorker.getId()+"");
        //System.out.println(tPartPatternAssemblyModel.getPatternAssemblyId());

        tPartPatternAssemblyModelMapper.insert(tPartPatternAssemblyModel);
        return 1;
    }

    @Override
    public TPartPatternAssembly selectTPartPatternAssemblyById(String patternAssemblyId) {
        TPartPatternAssembly tPartPatternAssembly = tPartPatternAssemblyMapper.selectById(patternAssemblyId);
        return tPartPatternAssembly;
    }

    @Override
    public TPartPatternAssemblyModel selectTPartPatternAssemblyModelById(String patternAssemblyIdModel) {
        return tPartPatternAssemblyModelMapper.selectById(patternAssemblyIdModel);
    }

    @Override
    public int updateTPartPatternAssemblyModel(TPartPatternAssemblyModel tPartPatternAssemblyModel) {
        tPartPatternAssemblyModelMapper.updateById(tPartPatternAssemblyModel);

        return 1;
    }

    @Override
    public int updateTPartPatternAssembly(TPartPatternAssembly tPartPatternAssembly) {
        tPartPatternAssemblyMapper.updateById(tPartPatternAssembly);
        return 1;
    }

    @Override
    public int deleteTPartPatternAssemblyModelByIds(String Modelids) {
        String[] split = Modelids.split(",");
        for (String s:split){
            tPartPatternAssemblyModelMapper.deleteById(s);
        }
        return 1;
    }

    @Override
    public int deleteTPartPatternAssemblyByIds(String ids) {
        String[] split = ids.split(",");
        for (String s:split){
            tPartPatternAssemblyMapper.deleteById(s);
        }
        return 1;
    }

}
